package com.jingming.consult.network.utils;

import android.content.Context;


import com.jingming.consult.bean.BaseBean;

import io.reactivex.Observer;
import io.reactivex.annotations.NonNull;
import io.reactivex.disposables.Disposable;

/**
 * 继承方式
 *
 * @param <T>
 */
public abstract class NetInheritObserver<T extends BaseBean> extends RxNetObserver<T> implements Observer<T> {

    public NetInheritObserver(Context context) {
        super(context);
    }

    @Override
    public void onComplete() {

    }

    @Override
    public final void onSubscribe(Disposable disposable) {
        try {
            onSubscribed(disposable);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public final void onNext(@NonNull T info) {
        if (info == null) {
            try {
                onFail( "onNext method parameter is empty");
            } catch (Exception e) {
                e.printStackTrace();
            }
            return;
        }
        if (info.getCode() == RESPONSE_CODE_OK) {
            try {
                onSuccess(info,null);
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else {
            //对服务器返回的通用问题的统一拦截处理
//            if (con != null && con.get() != null) {
//                DeviceInfo.analysisCode(con.get(), info.getCode(), info.getErrorMsg());
//            }
//            try {
//                onFail(info.getCode(), info.getErrorMsg(),null);
//            } catch (Exception e) {
//                e.printStackTrace();
//            }
        }
    }

    @Override
    public final void onError(@NonNull Throwable t) {
        error(t);
    }

}
